//https://leetcode.cn/problems/7WHec2/
#include <iostream>

class Solution {
public:
   ListNode* sortList(ListNode* head) {
    if (head == nullptr || head->next == nullptr) {
        return head;
    }

    // 将链表转换为 vector
    std::vector<int> vec;
    ListNode* current = head;
    while (current != nullptr) {
        vec.push_back(current->val);
        current = current->next;
    }

    // 使用 std::sort 对 vector 进行排序
    std::sort(vec.begin(), vec.end());

    // 将排序后的元素复制回链表
    current = head;
    for (int val : vec) {
        current->val = val;
        current = current->next;
    }

    return head;
    }
 
};